<?

$local_connect = $GLOBALS['master_db'];
$dns_dom_id = $GLOBALS['dns_dom_id'];
$dom = dns_dom_settings($dns_dom_id);

if(!$dom){
	$erorMsg = 'error_dns_dom_settins';
	include_once('errorMsg.html');
	exit;
}

$query = "SELECT address FROM dns_cluster.addresses WHERE type='store' ORDER BY used LIMIT 1";
$local_connect->query($query);
$dom_a_record = $local_connect->getNext();
$store_default_ip = $dom_a_record['address'];

if($dom['open_store'] == 't'){
	$dom_a_record = get_domain_records($dns_dom_id, array('r.type'=>'A','r.name'=>$dom['dns_dom_name']));
	$a_record = $dom_a_record[0]['content'];
	$checked = 'checked';
	$disabled = '';
	$params = "'open_store::yes|store_a_record' + document.getElementById('store_a_record').value";
}elseif($dom['open_store'] == 'f'){
	$a_record = $store_default_ip;
	$checked = '';
	$disabled = 'disabled';
	$params = '';
}

?>
<form id='sform' name='sform' onSubmit="return false;">
	<div>
		<br /><b>Edit A Record</b><br />
		<br />By default your domain name has been set to show your online hosting store. You can point the 'www' of your domain to another website though keeping its Private DNS enabled. This is done by changing the A Record of your domain. By disabling 'www' your domain name will not open a website at all, but your Private DNS will still be working smoothly.<br /><br />
	</div>
	<div>
		<table class="selected_dns" width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td align=right>Enable and use 'www' with the A Record below: </td>
				<td><input type="checkbox" name="open_store" id="open_store" onClick="store_ip = '<? echo $a_record; ?>';store_settings(this.checked);" value="yes" <?echo $checked; ?>></td>
			</tr>
                        <tr>
                                <td align=right>Point 'www' to the following IP: </td>
                                <td><input type="text" name="store_a_record" id="store_a_record" value = "<? echo $a_record; ?>" <?echo $disabled; ?>></td>
                        </tr>
			<tr>
				<td align=center colspan=2>
					<br />
					<input type=hidden name='dns_dom_id' id='dns_dom_id' value="<? echo $dns_dom_id; ?>">
					<input type="submit" value="Go Back" onClick="LoadPage('managednsDomains', '');var timeoutID = setTimeout('LoadDnsDomainInfo(\'dns_dom_id::<? echo $dns_dom_id; ?>\');',3000);">
					<input type="submit" value="Edit DNS" OnClick="change_store_settings(('take_action::change_a_record|' + fetchForm()));">
					<input type="submit" value = "Restore Default IP" onClick="document.getElementById('store_a_record').value = '<? echo $store_default_ip; ?>';">
				</td>
			</tr>
		</table>
	</div>
</form>

<?
echo "<script>
if('$checked' == 'checked'){
	store_settings('checked');
}
</script>";
?>